// 
Shader "Unlit/templateUnilit"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Color ("Color", Color) = (1,1,1,1)
        _Matcap ("Matcap", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma fragmentoption ARB_precision_hint_fastest // 快速
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
              float3 normal : NORMAL;

            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
              float3 normal : NORMAL;
                float3 worldNormal : NORMAL1;
                    float3 viewNormal : NORMAL2;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                o.worldNormal = UnityObjectToWorldNormal(v.normal);
                // o.viewNormal =mul((float3x3)UNITY_MATRIX_IT_MV,v.normal) ;
                o.viewNormal =mul(UNITY_MATRIX_IT_MV,v.normal) ;
                o.cap.xy = viewNormal.xy *0.5 + 0.5;
                return o;
            }

            sampler2D _Matcap;
            float4 _Color;
            float4 frag (v2f i) : SV_Target

            fixed4 frag (v2f i) : SV_Target
            {
                float3 normalColor = (i.viewNormal);
              return float4(normalColor,1.0);
                // sample the texture
                fixed4 col = tex2D(_MainTex, i.uv);
                float4 mc =tex2D(_Matcap,i.cap.xy);
                mc = _Color*mc*unity_ColorSpaceDouble;
                //unity_ColorSpaceDouble是unity的亮度补偿，liner是2，gamma是4.多
                // apply fog
                UNITY_APPLY_FOG(i.fogCoord, mc);
                return mc;
            }
            ENDCG
        }
    }
}
